<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>06_JS函数</title>
</head>
<body>
<script>
    function f1(){
        console.log('f1被调用了!');
    }
    f1();

    function f2(n){//形参
        console.log('f2被调用了!');
        console.log(n);
    }
    f2(10);//实参
    f2(true);
    f2('哈哈哈');

    //实参个数大于形参个数,多余的实参会被舍弃掉
    //实参个数小于形参个数,未被赋值的形参值为undefined
    function f3(x,y){
        console.log('f3被调用了!');
        console.log(x+y);
    }
    f3(10,20);//30
    f3(20,30,70);//50
    f3(20);//20+undefined=NaN

    //函数有返回值
    function f4(a,b){
        console.log('f4被调用了!');
        return a+b;
    }
    console.log(f4(10,20));
    var res = f4(10,20);
    console.log(res);

    //f5变量保存了函数的全部内容,变量名就充当了函数名
    var f5 = function(){
        console.log('f5被调用了!');
    }
    console.log(typeof f5);//function
    console.log(f5);//ƒ (){console.log('f5被调用了!');}
    f5();

    //箭头函数
    //将函数整体交给常量f6来保存,调用时直接将常量名当做方法名调用即可
    const f6 = ()=>{
        console.log('f6被调用了!');
    }
    f6();
</script>
</body>
</html>